package com.sxyjhh.fg_data_push.utils.entity;

import com.sxyjhh.fg_data_push.utils.Constants;
import com.sxyjhh.fg_data_push.utils.IdGenerator;
import org.apache.commons.lang.StringUtils;

import java.util.Date;

/**
 * Class description:所有实体类的基础父类
 * @JDK Version:  1.8.0_40
 * @version       V1.0, 2016.02.26 at 05:32:20 CST
 * @Author        Shaok Lei
 */
public class BaseEntity {

    /** Field description：主键标识 */
    private String id;

    /** Field description：数据状态（1：正常；2：删除；0：状态无效） */
    private String dataFlag;

    /** Field description ：描述 */
    private String description;

    /** Field description ：创建人ID */
    private String createrId;

    /** Field description ：创建时间 */
    private Date createTime;

    /** Field description ：修改人ID */
    private String modifyId;

    /** Field description： 修改时间 */
    private Date modifyTime;

    public BaseEntity() {}

    /**
     * Method description：
     * Version:V1.0
     * Author:Shaok Lei
     * Date:2016.02.26 at 05:32:20 CST
     * @return
     */
    public Date getCreateTime() {
        return createTime;
    }

    /**
     * Method description：
     * Version:V1.0
     * Author:Shaok Lei
     * Date:2016.02.26 at 05:32:20 CST
     *
     * @param createTime
     */
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    /**
     * Method description：
     * Version:V1.0
     * Author:Shaok Lei
     * Date:2016.02.26 at 05:32:20 CST
     * @return
     */
    public String getCreaterId() {
        return createrId;
    }

    /**
     * Method description：
     * Version:V1.0
     * Author:Shaok Lei
     * Date:2016.02.26 at 05:32:20 CST
     *
     * @param createrId
     */
    public void setCreaterId(String createrId) {
        this.createrId = createrId;
    }

    /**
     * Method description：
     * Version:V1.0
     * Author:Shaok Lei
     * Date:2016.02.26 at 05:32:20 CST
     * @return
     */
    public String getDataFlag() {
        return dataFlag;
    }

    /**
     * Method description：
     * Version:V1.0
     * Author:Shaok Lei
     * Date:2016.02.26 at 05:32:20 CST
     *
     * @param dataFlag
     */
    public void setDataFlag(String dataFlag) {
        this.dataFlag = dataFlag;
    }

    /**
     * Method description：
     * Version:V1.0
     * Author:Shaok Lei
     * Date:2016.02.26 at 05:32:20 CST
     * @return
     */
    public String getDescription() {
        return description;
    }

    /**
     * Method description：
     * Version:V1.0
     * Author:Shaok Lei
     * Date:2016.02.26 at 05:32:20 CST
     *
     * @param description
     */
    public void setDescription(String description) {
        this.description = description;
    }

    /**
     * Method description：
     * Version:V1.0
     * Author:Shaok Lei
     * Date:2016.02.26 at 05:32:20 CST
     * @return
     */
    public String getId() {
        return id;
    }

    /**
     * Method description：
     * Version:V1.0
     * Author:Shaok Lei
     * Date:2016.02.26 at 05:32:20 CST
     *
     * @param id
     */
    public void setId(String id) {
        this.id = id;
    }

    /**
     * Method description：数据插入前的操作
     * Version:V1.0
     * Author:Shaok Lei
     * Date:2016.02.26 at 05:37:57 CST
     */
    public void setInsertBefore() {

        // 插入数据前设置创建时间、修改时间和数据状态
        if(StringUtils.isBlank(this.getId())){
            this.setId(IdGenerator.createNewId());
        }

        Date dateTime = new Date();
        this.setCreateTime(dateTime);
        this.setModifyTime(dateTime);
        this.setDataFlag(Constants.DATA_FLAG_OK);
    }

    /**
     * Method description：
     * Version:V1.0
     * Author:Shaok Lei
     * Date:2016.02.26 at 05:32:20 CST
     * @return
     */
    public String getModifyId() {
        return modifyId;
    }

    /**
     * Method description：
     * Version:V1.0
     * Author:Shaok Lei
     * Date:2016.02.26 at 05:32:20 CST
     *
     * @param modifyId
     */
    public void setModifyId(String modifyId) {
        this.modifyId = modifyId;
    }

    /**
     * Method description：
     * Version:V1.0
     * Author:Shaok Lei
     * Date:2016.02.26 at 05:32:20 CST
     * @return
     */
    public Date getModifyTime() {
        return modifyTime;
    }

    /**
     * Method description：
     * Version:V1.0
     * Author:Shaok Lei
     * Date:2016.02.26 at 05:32:20 CST
     *
     * @param modifyTime
     */
    public void setModifyTime(Date modifyTime) {
        this.modifyTime = modifyTime;
    }

    /**
     * Method description：修改前自动设置修改时间
     * Version:V1.0
     * Author:Shaok Lei
     * Date:2016.02.26 at 05:36:11 CST
     */
    public void setUpdateBefore() {
        this.modifyTime = new Date();
    }
}
